#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);
    int w = this->width();
    int h = this->height();
    int side = qMin(w, h);
    QRect rect((w - side) / 2, (h - side) / 2, side, side);
    painter.drawRect(rect);
    painter.setViewport(rect);
    painter.setWindow(-100, -100, 200, 200);
    painter.setRenderHint(QPainter::Antialiasing);
    //设置画笔
    QPen pen;
    pen.setWidth(1);
    pen.setColor(Qt::GlobalColor::red);
    pen.setStyle(Qt::PenStyle::SolidLine);
    painter.setPen(pen);
    //线性渐变
    QLinearGradient linearGrad(0, 0, 100, 0);
    linearGrad.setColorAt(0, Qt::GlobalColor::yellow);
    linearGrad.setColorAt(1, Qt::GlobalColor::green);
    linearGrad.setSpread(QGradient::PadSpread);
    painter.setBrush(linearGrad);
    //设置复合模式
    painter.setCompositionMode(QPainter::CompositionMode::RasterOp_NotSourceXorDestination);
    //画画
    for (int i = 0; i < 36; i++) {
        painter.drawEllipse(QPoint(50, 0), 50, 50);
        painter.rotate(10);
    }
}

